﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Rodunu.Movies.Contracts;
using Rodunu.Movies.Interfaces.User;
using Rodunu.Movies.Logic.User;

namespace Rodunu.Movies.Web.Utility
{
    public static class CommentsHelper
    {
        public static string BuildSmallComment(Comments comments, bool isLarge)
        {
            IUser userLogic = new UserLogic();
            UserInfo user = userLogic.Find(comments.UserId);
            var sb = new StringBuilder();

            sb.Append("<div class='CommentArrow'>");
            sb.Append("<img src='../Content/img/CommentsArrow.jpg' />");
            sb.Append("</div>");
            if (isLarge)
                sb.Append("<div class='LargeCommentBox'>");
            else
                sb.Append("<div class='SmallCommentBox'>");
            sb.Append("<div class='avatar'>");
            if (string.IsNullOrEmpty(user.Avatar))
                sb.Append("<img id='UserAvatar' style='max-width: 35px; max-height: 35px' src='../Content/img/blank_avatar.jpg' />");
            else
            {
                sb.Append("<img id='UserAvatar' style='max-width: 35px; max-height: 35px' src='../Uploads/");
                sb.Append(user.Id);
                sb.Append(@"/Avatars/");
                sb.Append(user.Avatar);
                sb.Append("' >");
            }
            sb.Append("</div>");

            sb.Append("<div class='info'>");
            sb.Append("<div class='user'>");
            if (user.ShowProfile)
            {
                sb.Append("<a href='../User/UserInfo.ashx?userName=");
                sb.Append(user.UserName);
                sb.Append("'>");
                sb.Append(user.UserName);
                sb.Append("</a>");
            }
            else
                sb.Append(user.UserName);
            sb.Append("</div>");
            sb.Append("<div class='time'>");
            sb.Append("at ");
            sb.Append(comments.DateAdded.ToShortTimeString());
            sb.Append(" ");
            sb.Append(string.Format("{0:MMMM d}", comments.DateAdded));
            sb.Append("</div>");
            sb.Append("<div class='commenttext'>");
            sb.Append(comments.Comment);
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("</div>");

            return sb.ToString();
        }
    }
}
